//
//  CitySelectTableViewCell.m
//  beautyAccompany
//
//  Created by xiaocankeji on 15/11/18.
//  Copyright © 2015年 xiaocankeji. All rights reserved.
//

#import "CitySelectTableViewCell.h"
#define kCityBTTag 123
#define kBtSpace 20
#define kRightSpace 15
#define kBtTopSpace 10
#define kBtHeight 40

@implementation CitySelectTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cityCount:(NSUInteger)cityCount
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = RGBA(244, 244, 244, 1);
        
        
        CGFloat btW = (DeviceWidth - 4*kBtSpace - kRightSpace)/3;
        for (int i = 0; i<cityCount; i++) {
            
            UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
            bt.tag = i+kCityBTTag;
            bt.frame = CGRectMake(kBtSpace +((i%3) * (btW +kBtSpace)), kBtTopSpace+((i/3)*(kBtHeight+kBtTopSpace)), btW, kBtHeight);
            bt.layer.borderColor = RGBA(222, 222, 222, 1).CGColor;
            bt.layer.borderWidth = 0.5;
            bt.titleLabel.font = kFont(15);
            [bt setTitleColor:RGBA(88, 88, 88, 1) forState:UIControlStateNormal];
            [bt setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
             [bt setBackgroundImage:[UIImage imageWithColor:RGBA(188, 188, 188, 1)] forState:UIControlStateHighlighted];
            [bt addTarget:self action:@selector(clickCityBt:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:bt];
            
        }
    }
    return self;
}
- (void)setCityArr:(NSArray *)cityArr
{
    _cityArr = cityArr;
    for (int i = 0; i<cityArr.count; i++) {
        UIButton *bt = (UIButton *)[self viewWithTag:kCityBTTag+i];
        [bt setTitle:cityArr[i] forState:UIControlStateNormal];
    }
}
- (void)clickCityBt:(UIButton *)bt
{
    if([_delegate respondsToSelector:@selector(selectCity:)])
    {
        [_delegate selectCity:bt.titleLabel.text];
    }
}
//cell的高度
+(CGFloat)CitySelectTableViewHeightCityCount:(NSUInteger)count
{
    return kBtTopSpace+(count/3+1)*(kBtHeight+kBtTopSpace);
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
